<template>
  <div class="meat">
    <!-- 一级菜单下面所拥有的二级菜单 -->
    <el-aside class="aside" :width="isCollapse ? '50px' : '200px'">
      <i
        class="el-icon-s-fold toggle-button"
        @click="toggleCollapse"
        v-if="isCollapse == false"
      ></i>
      <i
        class="el-icon-s-unfold toggle-button"
        @click="toggleCollapse"
        v-else
      ></i>
      <el-menu
        ref="menu"
        :default-active="activePath"
        router
        unique-opened
        :collapse-transition="false"
        :collapse="isCollapse"
        class="sidebar el-menu-vertical-demo"
        @select="openMenu"
        text-color="#A9B0B7"
        active-text-color="#0064F1"
      >
        <menu-tree :menuData="treeData"></menu-tree>
      </el-menu>
    </el-aside>
    <!-- 以及二级菜单所对应的页面 -->
    <el-main class="main_container">
      <router-view></router-view>
    </el-main>
  </div>
</template>

<script>
import menuTree from "@/components/commonPublic/menu.vue";
import { getBaseModuleList } from "@/api/request.js";
export default {
  components: {
    // SideMenu
    menuTree,
  },
  data() {
    return {
      activePath: "",
      isCollapse: false,
      // 材料质量管控
      treeData: [
        // 原材料管理
        {
          title: "材料进场管理",
          img: "iconfont icon-xitongguanli1",
          name: "rawMaterialManage",
          left: 0,
          children: [
            {
              title: "材料进场台帐",
              path: "entryLedger",
              path2: "entryLedgerText",
              name: "entryLedger",
              name2: "entryLedgerText",
              img: "iconfont icon-shengchanguanli1",
              children: [],
              left: 37,
            },
            {
              title: "材料检测台帐",
              path: "inspectionLedger",
              path2: "",
              name: "inspectionLedger",
              name2: "",
              img: "iconfont icon-shengchanguanli1",
              children: [],
              left: 37,
            },
          ],
        },
        // 见证取样管理
        {
          title: "材料见证取样",
          img: "iconfont icon-xitongguanli1",
          name: "sampleManage",
          children: [
            {
              title: "现场见证取样",
              path: "fieldSampling",
              path2: "fieldSamplingText",
              name: "fieldSampling",
              name2: "fieldSamplingText",
              img: "iconfont icon-shengchanguanli1",
              children: [],
              left: 37,
            },
            {
              title: "样品室内收样",
              path: "collection",
              path2: "collectionText",
              name: "collection",
              name2: "collectionText",
              img: "iconfont icon-shengchanguanli1",
              children: [],
              left: 37,
            },
            // {
            //   title: "材料检测委托单",
            //   path: "sampleMaterial",
            //   path2: "sampleMaterialText",
            //   name: "sampleMaterial",
            //   name2: "sampleMaterialText",
            //   img: "iconfont icon-shengchanguanli1",
            //   children: [],
            //   left: 37,
            // },
          ],
        },
        // 智能养护管理
        {
          rank: 1,
          title: "智能养护管理",
          img: "iconfont icon-xitongguanli1",
          name: "intelligentMaintenanceManage",
          left: 0,
          children: [
            {
              title: "试件入库管理",
              path: "sampleStorage",
              path2: "",
              name: "sampleStorage",
              name2: "",
              img: "iconfont icon-shengchanguanli1",
              children: [],
              left: 37,
            },
            {
              title: "试件出库管理",
              path: "sampleOutbound",
              path2: "",
              name: "sampleOutbound",
              name2: "",
              img: "iconfont icon-shengchanguanli1",
              children: [],
              left: 37,
            },
            {
              title: "温湿度在线监控",
              path: "temperatureAndhumidity",
              path2: "",
              name: "temperatureAndhumidity",
              name2: "",
              img: "iconfont icon-shengchanguanli1",
              children: [],
              left: 37,
            },
          ],
        },
        // 试验机联网
        {
          rank: 1,
          title: "试验机联网监管",
          img: "iconfont icon-xitongguanli1",
          name: "machineNetworkManage",
          left: 0,
          children: [
            {
              path: "sampleTestedManage",
              path2: "",
              img: "iconfont icon-shengchanguanli1",
              children: [],
              title: "待试验样品",
              name: "sampleTestedManage",
              left: 37,
            },

            {
              title: "试验数据监控",

              name: "testDataMonitorManage",
              img: "iconfont icon-gongcheng",
              left: 25,
              children: [
                {
                  title: "压力机数据监控",
                  path: "pressDataMonitor",
                  path2: "",
                  img: "iconfont icon-cailiaozhengli",
                  children: [],
                  name: "pressDataMonitor",
                  left: 60,
                },

                {
                  title: "万能机数据监控",
                  path: "zigzagDataMonitor",
                  path2: "",
                  img: "iconfont icon-cailiaozhengli",
                  children: [],
                  name: "zigzagDataMonitor",
                  left: 60,
                },
                {
                  title: "抗折抗压机数据监控",
                  path: "compressivePressDataMonitor",
                  path2: "",
                  img: "iconfont icon-cailiaozhengli",
                  children: [],
                  name: "compressivePressDataMonitor",
                  left: 60,
                },
                {
                  title: "沥青设备监控",

                  img: "iconfont icon-shengchengbaogao",
                  name: "asphaltEquipmentMonitor",
                  left: 45,
                  children: [
                    {
                      title: "针入度",
                      path: "penetrationMonitor",
                      path2: "",
                      img: "iconfont icon-cailiaozhengli",
                      children: [],
                      name: "penetrationMonitor",
                      left: 80,
                    },

                    {
                      title: "软化点",
                      path: "softenPointMonitor",
                      path2: "",
                      img: "iconfont icon-cailiaozhengli",
                      children: [],
                      name: "softenPointMonitor",
                      left: 80,
                    },
                    {
                      title: "延度",
                      path: "ductilityMonitor",
                      path2: "",
                      img: "iconfont icon-cailiaozhengli",
                      children: [],
                      name: "ductilityMonitor",
                      left: 80,
                    },
                  ],
                },
                {
                  title: "沥青混合料监控",

                  img: "iconfont icon-shengchengbaogao",

                  name: "asphaltMixtureMonitor",
                  left: 45,
                  children: [
                    {
                      title: "稳定度",
                      path: "stabilityMonitor",
                      path2: "",
                      img: "iconfont icon-cailiaozhengli",
                      children: [],
                      name: "stabilityMonitor",
                      left: 80,
                    },

                    {
                      title: "沥青含量",
                      path: "asphaltContentMonitor",
                      path2: "",
                      img: "iconfont icon-cailiaozhengli",
                      children: [],
                      name: "asphaltContentMonitor",
                      left: 80,
                    },
                    {
                      title: "车辙",
                      path: "rutMonitor",
                      path2: "",
                      img: "iconfont icon-cailiaozhengli",
                      children: [],
                      name: "rutMonitor",
                      left: 80,
                    },
                  ],
                },
              ],
            },
            {
              title: "试验数据处理",
              name: "testDataProcessManage",
              img: "iconfont icon-gongcheng",
              left: 25,
              children: [
                {
                  title: "压力机数据处理",
                  path: "pressDataProcess",
                  path2: "",
                  img: "iconfont icon-cailiaozhengli",
                  children: [],
                  name: "pressDataProcess",
                  left: 60,
                },

                {
                  title: "万能机数据处理",
                  path: "zigzagDataProcess",
                  path2: "",
                  img: "iconfont icon-cailiaozhengli",
                  children: [],
                  name: "zigzagDataProcess",
                  left: 60,
                },
                {
                  title: "抗折抗压机数据处理",
                  path: "compressivePressDataProcess",
                  path2: "",
                  img: "iconfont icon-cailiaozhengli",
                  children: [],
                  name: "compressivePressDataProcess",
                  left: 60,
                },
                {
                  title: "沥青设备处理",
                  img: "iconfont icon-shengchengbaogao",
                  name: "asphaltEquipmentProcess",
                  left: 45,
                  children: [
                    {
                      title: "针入度",
                      path: "penetrationProcess",
                      path2: "",
                      img: "iconfont icon-cailiaozhengli",
                      children: [],
                      name: "penetrationProcess",
                      left: 80,
                    },

                    {
                      title: "软化点",
                      path: "softenPointProcess",
                      path2: "",
                      img: "iconfont icon-cailiaozhengli",
                      children: [],
                      name: "softenPointProcess",
                      left: 80,
                    },
                    {
                      title: "延度",
                      path: "ductilityProcess",
                      path2: "",
                      img: "iconfont icon-cailiaozhengli",
                      children: [],
                      name: "ductilityProcess",
                      left: 80,
                    },
                  ],
                },
                {
                  title: "沥青混合料处理",
                  img: "iconfont icon-shengchengbaogao",
                  name: "asphaltMixtureProcess",
                  left: 45,
                  children: [
                    {
                      title: "稳定度",
                      path: "stabilityProcess",
                      path2: "",
                      img: "iconfont icon-cailiaozhengli",
                      children: [],
                      name: "stabilityProcess",
                      left: 80,
                    },

                    {
                      title: "沥青含量",
                      path: "asphaltContentProcess",
                      path2: "",
                      img: "iconfont icon-cailiaozhengli",
                      children: [],
                      name: "asphaltContentProcess",
                      left: 80,
                    },
                    {
                      title: "车辙",
                      path: "rutProcess",
                      path2: "",
                      img: "iconfont icon-cailiaozhengli",
                      children: [],
                      name: "rutProcess",
                      left: 80,
                    },
                  ],
                },
              ],
            },
            {
              title: "数据统计分析",
              name: "analysisDataManage",
              img: "iconfont icon-gongcheng",
              left: 25,
              children: [
                {
                  title: "混凝土质量趋势",
                  path: "concreteQuality",
                  path2: "",
                  img: "iconfont icon-cailiaozhengli",
                  children: [],
                  name: "concreteQuality",
                  left: 60,
                },

                {
                  title: "钢筋质量趋势",
                  path: "rebarQuality",
                  path2: "",
                  img: "iconfont icon-cailiaozhengli",
                  children: [],
                  name: "rebarQuality",
                  left: 60,
                },
                {
                  title: "水泥质量趋势",
                  path: "cementQuality",
                  path2: "",
                  img: "iconfont icon-cailiaozhengli",
                  children: [],
                  name: "cementQuality",
                  left: 60,
                },
                {
                  title: "砂浆质量趋势",
                  path: "mortarQuality",
                  path2: "",
                  img: "iconfont icon-cailiaozhengli",
                  children: [],
                  name: "mortarQuality",
                  left: 60,
                },
                {
                  title: "净浆质量趋势",
                  path: "pasteQuality",
                  path2: "",
                  img: "iconfont icon-cailiaozhengli",
                  children: [],
                  name: "pasteQuality",
                  left: 60,
                },
              ],
            },
          ],
        },
        // 试验检测管理
        {
          rank: 1,
          title: "试验检测管理",
          img: "iconfont icon-xitongguanli1",
          name: "testDetectionManage",
          left: 0,
          children: [
            {
              title: "备案信息管理",
              //1只有查看    2带编辑页
              path: "filing",
              path2: "",
              name: "filing",
              name2: "",
              img: "iconfont icon-shengchanguanli1",
              children: [],

              left: 37,
            },
            {
              title: "样品登记台帐",
              //1只有查看    2带编辑页
              path: "samplesLedger",
              path2: "",
              name: "samplesLedger",
              name2: "",
              img: "iconfont icon-shengchanguanli1",
              children: [],
              left: 37,
            },
            {
              title: "检测报告台帐",
              //1只有查看    2带编辑页
              path: "testingLedger",
              path2: "",
              name: "testingLedger",
              name2: "",
              img: "iconfont icon-shengchanguanli1",
              children: [],
              left: 37,
            },
            {
              title: "不合格报告管理",
              //1只有查看    2带编辑页
              path: "unqualifiedReport",
              path2: "",
              name: "unqualifiedReport",
              name2: "",
              img: "iconfont icon-shengchanguanli1",
              children: [],
              left: 37,
            },

            {
              title: "材料报验单管理",
              path: "InspectionForm",
              path2: "InspectionFormText",
              name: "InspectionForm",
              name2: "InspectionFormText",
              img: "iconfont icon-shengchanguanli1",
              children: [],
              left: 37,
            },
          ],
        },
        // 外委检测管理
        {
          rank: 1,
          title: "外委检测管理",
          img: "iconfont icon-xitongguanli1",
          name: "outsourcedManage",
          left: 0,
          children: [
            {
              title: "外委样品管理",
              path: "outsourcedSample",
              path2: "outsourcedSampleText",
              name: "outsourcedSample",
              name2: "outsourcedSampleText",
              img: "iconfont icon-shengchanguanli1",
              children: [],
              left: 37,
            },
            {
              title: "外委报告管理",
              path: "qualificationReport",
              path2: "qualificationReportText",
              name: "qualificationReport",
              name2: "qualificationReportText",
              img: "iconfont icon-shengchanguanli1",
              children: [],
              left: 37,
            },
            {
              title: "不合格报告管理",
              path: "outUnQualifiedReports",
              path2: "outUnQualifiedReportsText",
              name: "outUnQualifiedReports",
              name2: "outUnQualifiedReportsText",
              img: "iconfont icon-shengchanguanli1",
              children: [],
              left: 37,
            },
          ],
        },
        // 试验室综合管理
        {
          rank: 1,
          title: "试验室综合管理",
          img: "iconfont icon-xitongguanli1",
          name: "constructionSiteLaboratoryManage",
          left: 0,
          children: [
            {
              title: "试验室备案信息",
              path: "laboratoryInformation",
              path2: "",
              name: "laboratoryInformation",
              name2: "",
              img: "iconfont icon-shengchanguanli1",
              children: [],
              left: 37,
            },
            {
              title: "检测人员管理",
              path: "testPersonnelInfo",
              path2: "testPersonnelInfoText",
              name: "testPersonnelInfo",
              name2: "testPersonnelInfoText",
              img: "iconfont icon-shengchanguanli1",
              children: [],
              left: 37,
            },
            {
              title: "仪器设备信息",
              path: "instrumentEquipmentInfo",
              path2: "instrumentEquipmentInfoText",
              name: "instrumentEquipmentInfo",
              name2: "instrumentEquipmentInfoText",
              img: "iconfont icon-shengchanguanli1",
              children: [],
              left: 37,
            },
            {
              title: "设备检定校准",
              path: "equipmentVerificationCalibration",
              path2: "equipmentVerificationCalibrationText",
              name: "equipmentVerificationCalibration",
              name2: "equipmentVerificationCalibrationText",
              img: "iconfont icon-shengchanguanli1",
              children: [],
              left: 37,
            },
            {
              title: "设备使用记录",
              path: "equipmentUsageRecord",
              path2: "",
              name: "equipmentUsageRecord",
              name2: "",
              img: "iconfont icon-shengchanguanli1",
              children: [],
              left: 37,
            },
          ],
        },
      ],
    };
  },
  watch: {
    activePath() {
      this.activePath = sessionStorage.getItem("yjSmart-keyPath");
    },
  },
  mounted() {
    this.activePath =
      sessionStorage.getItem("yjSmart-keyPath") || "entryLedger";
    this.roleModule();
  },
  methods: {
    roleModule() {
      var ModuleList = JSON.parse(sessionStorage.getItem("yjSmart-ModuleList"));
      var fristModule = [];
      if (ModuleList.length != 0) {
        this.treeData.map((i) => {
          //筛选大模块
          ModuleList.map((item) => {
            if (item.fEncode == i.name) {
              i.title = item.fFullname;
              fristModule.push(i);
            }
          });
        });

        fristModule.map((item) => {
          //只有两级
          item["childrens"] = [];
          item.children.map((i) => {
            ModuleList.map((j) => {
              if (i.name == j.fEncode) {
                // console.log(i, j);
                i.title = j.fFullname;
                item["childrens"].push(i);
              }
            });
          });
          item.children = item.childrens;
        });
        // 有三级
        fristModule.map((item) => {
          item.children.map((i) => {
            //二级
            i["childrens"] = [];
            i.children.map((h) => {
              //循环3级
              ModuleList.map((j) => {
                if (h.name == j.fEncode) {
                  h.title = j.fFullname;
                  i["childrens"].push(h);
                }
              });
            });

            i.children = i.childrens;
          });
        });

        fristModule.map((item) => {
          item.children.map((i) => {
            if (i.rank == 2) {
              i.path2 = "";

              ModuleList.map((j) => {
                if (i.name2 == j.fEncode) {
                  i.path2 = i.path + "Text";
                }
              });
            }
          });
        });

        this.treeData = fristModule;
      } else if (
        JSON.parse(sessionStorage.getItem("yjSmart-userInfo")).enCode ==
        "System"
      ) {
        this.getTree();
      } else {
        this.treeData = [];
        return this.$message.error("请配置对应权限");
      }
    },

    leftNameDataData(val, data) {
      // val:树接口  data:本地
      let list = [];
      if (!Array.isArray(data)) {
        return list;
      }
      list = data.map((item) => {
        if (item.children.length > 0) {
          this.leftNameDataData(val, item.children);
        }
        val.map((i) => {
          // 接口等于本地
          if (i.fEncode == item.name) {
            item.title = i.fFullname;
          }
        });

        return item;
      });

      return list;
    },
    getTree() {
      getBaseModuleList({
        fModuleid: "",
      })
        .then((res) => {
          if (res.errcode == 0) {
            var companyTree = res.data.baseModuleList;
            this.treeData = this.leftNameDataData(companyTree, this.treeData);
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch(() => {
          return false;
        });
    },
    // 左侧菜单是否显示
    toggleCollapse() {
      this.isCollapse = !this.isCollapse;
    },
    openMenu(keyPath) {
      //  window.sessionStorage.setItem("yjSmart-materiaMange-meun", keyPath);
      if (keyPath != "null") {
        sessionStorage.setItem("yjSmart-keyPath", keyPath);
      }
    },
    handleNodeClick(data) {
      console.log(data, 3333);
    },
  },
};
</script>
